package com.behome.socket_proxy.netty_D.server;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import io.netty.handler.codec.bytes.ByteArrayDecoder;
import io.netty.handler.codec.bytes.ByteArrayEncoder;
import io.netty.handler.timeout.IdleStateHandler;

/**
 * @ClassName StandardDNettyServerChannelInitializer
 * @Description 服务端初始化，客户端与服务器端连接一旦创建，这个类中方法就会被回调，设置出站编码器和入站解码器
 * @Author Gcf
 * @Date 2021/8/10
 **/
public class StandardDNettyServerChannelInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel channel) {
//        channel.pipeline().addLast(new LengthFieldBasedFrameDecoder(8192,10,2,-12,0));
        channel.pipeline().addLast(new ByteArrayDecoder());
        channel.pipeline().addLast(new ByteArrayEncoder());
        channel.config().setWriteBufferHighWaterMark(1024 * 1024 * 8);
        channel.pipeline().addLast(new IdleStateHandler(0, 1, 0), new StandardDNettyServerHandler());
    }

}
